package com.orange.adminapi.controller.shop;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orange.core.pojo.BR;
import com.orange.core.pojo.PageReqDto;
import com.orange.core.pojo.R;
import com.orange.core.pojo.entity.shop.dto.ShopDTO;
import com.orange.core.pojo.entity.shop.vo.ShopVO;
import com.orange.core.pojo.req.shop.ShopPageReq;
import com.orange.core.service.shop.ShopService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>ClassName:ShopController</p>
 * <p>Description: 品牌商铺Controller</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/6/1 21:00</p>
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/shop")
public class ShopController {

    private final ShopService shopService;

    /**
     * 品牌商铺分页查询
     * @param pageReqDto
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).BRAND_LIST.permission.identifier)")
    @PostMapping("/page")
    public R<Page<ShopVO>> page(@RequestBody PageReqDto<ShopPageReq> pageReqDto){
        Page<ShopVO> page = shopService.page(pageReqDto);
        return R.ok(page);
    }

    /**
     * 品牌商铺详情
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).BRAND_INFO.permission.identifier)")
    @GetMapping("/info/{id}")
    public R<ShopVO> info(@PathVariable("id") int id){
        return R.ok(shopService.info(id));
    }

    /**
     * 品牌商铺新增
     * @param shopDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).BRAND_SAVE.permission.identifier)")
    @PostMapping
    public R<Boolean> save(@RequestBody @Validated ShopDTO shopDTO){
        return BR.result(shopService.save(shopDTO));
    }

    /**
     * 品牌商铺修改
     * @param shopDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).BRAND_UPDATE.permission.identifier)")
    @PutMapping
    public R<Boolean> update(@RequestBody @Validated ShopDTO shopDTO){
        return BR.result(shopService.update(shopDTO));
    }

    /**
     * 品牌商铺批量删除(把物理删除，改为修改状态为停用）
     * @param ids
     * @return
     */
   /* @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).BRAND_DELETE.permission.identifier)")
    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable("ids") Integer[] ids) {
        return BR.result(shopService.deleteShopByIds(ids));
    }*/
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).BRAND_DELETE.permission.identifier)")
    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable("ids") Integer[] ids) {
        return BR.result(shopService.deleteShopByIds(ids));
    }
}
